﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace DroidLord.app.dy
{
    class DYGetGoodList
    {

        /// <summary>
        /// https://aweme.snssdk.com/aweme/v2/shop/discovery/feed/?request_tag_from=rn&area_id=1&category_id=0&page=33&size=20&storage_type=0&manifest_version_code=120001&_rticket=1596175236926&app_type=normal&iid=685690430690688&channel=aweGW&device_type=ONEPLUS+A3000&language=zh&cpu_support64=true&host_abi=armeabi-v7a&resolution=1080*1920&openudid=ef753a6e96787dab&update_version_code=12009900&cdid=8e7328e6-f8ac-49f2-81b6-de6ba5dad3f4&appTheme=dark&os_api=27&mac_address=C0%3AEE%3AFB%3AD6%3A8A%3A73&dpi=480&ac=wifi&device_id=68370507519&mcc_mnc=46011&os_version=8.1.0&version_code=120000&app_name=aweme&version_name=12.0.0&device_brand=OnePlus&ssmix=a&device_platform=android&aid=1128&ts=1596175234
        /// </summary>
        /// <returns></returns>
        public static String  getGoodList(String page)
        {
            String result = "";
            try
            {
                //anchor_info 字段存放商品信息
                //String myurl = "https://aweme.snssdk.com/aweme/v2/shop/discovery/feed/?request_tag_from=rn&area_id=1&category_id=1%2C2&page="+page+"&size=20&storage_type=0&manifest_version_code=120001&_rticket=1596175236926&app_type=normal&channel=aweGW&device_type=ONEPLUS+A3000&language=zh&cpu_support64=true&host_abi=armeabi-v7a&update_version_code=12009900&appTheme=dark&os_api=27&os_version=8.1.0&version_code=120000&app_name=aweme&version_name=12.0.0&device_brand=OnePlus&device_platform=android&aid=1128&ts="+GetTimeStamp(true);
                //promotions字段存放商品信息
                string myurl = "https://aweme.snssdk.com/aweme/v2/shop/discovery/feed/?request_tag_from=rn&area_id=1&category_id=0&page="+page+"&size=20&source_page=shopping_assistant&app_name=aweme&device_platform=android&aid=1128";
                HttpWebRequest myrequest = (HttpWebRequest)WebRequest.Create(myurl);
                myrequest.Method = "GET";
                myrequest.UserAgent = "Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; ONEPLUS A3000 Build/AL00) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/8.9 Mobile Safari/537.36";
                myrequest.AllowAutoRedirect = true;
                using (WebResponse wr = myrequest.GetResponse())
                {
                    StreamReader myStreamReader = new StreamReader(wr.GetResponseStream(), Encoding.GetEncoding("utf-8"));
                    result = myStreamReader.ReadToEnd();
                    myStreamReader.Close();
                }
                myrequest.Abort();
            }
            catch (Exception eee)
            {

            }
            return result;
        }

        public static string GetTimeStamp(bool bflag)
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string ret = string.Empty;
            if (bflag)
                ret = Convert.ToInt64(ts.TotalSeconds).ToString();
            else
                ret = Convert.ToInt64(ts.TotalMilliseconds).ToString();
            return ret;
        }


        public static void  saveFile(string path,string data)
        {
            try
            {
                StreamWriter streamWriter = new StreamWriter(path);
                streamWriter.Write(data);
                streamWriter.Flush();
                streamWriter.Close();
            }catch(Exception eeee)
            {

            }
        }
    }
}
